macroScript AnimationExport category:"AirCrash"
(
	select $Bone*

	output_name = getSaveFileName caption:"XML Animation File" types:"Level (*.anim)|*.anim|"
	
	if output_name != undefined then 
	(
		output_file = createfile output_name
		
		start = animationRange.start
		end = animationRange.end

		format "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" to:output_file
		format "<animation>\n" to:output_file
		
		for obj in selection do
		(
			id = getUserProp obj "id"
			
			format "\t<bone id=\"%\">\n" id to:output_file
			for t = start to end do
			(
				angles = (at time t obj.transform.rotation) as eulerangles
				rx = degToRad angles.x
				ry = degToRad angles.y
				rz = degToRad angles.z
				
				format "\t\t<rotation time=\"%\" rx=\"%\" ry=\"%\" rz=\"%\"></rotation>\n" t rx ry rz to:output_file
			)
			format "\t</bone>\n" to:output_file
		)
		format "</animation>\n" to:output_file
		
		close output_file
	)
	print "DONE"
)